import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

import java.util.Vector;

public class ThreadServer {

	static int ServPort = 4500;
	static int count = 0, i = 0;
	public static void main(String[] args) {
		
		//Create Logger to log Server Messages
		MyLogger ServerLog = new MyLogger("ServerData.log");
		
		//Create a Table Manager
		TableManager TManager = new TableManager();
		for(int i = 0; i < 5; i++)
		{
			TManager.TableList.add(new Table(i+1));
		}
		
		AllTableSocketList SList = new AllTableSocketList();
		//Create Server Socket
		ServerSocket ServSocket = null;
		try {
			ServSocket = new ServerSocket(ServPort);
			//Run Forever
			while(true)
			{
				ServerLog.logMessage("Listening for incoming connections on Port 4500: ");
				//Create Client Socket;
				Socket ClientSocket = ServSocket.accept();
				ServerLog.logMessage("Connection accepted from" + ClientSocket.getInetAddress().toString());
				//System.out.println("Connected to " + ClientSocket.getInetAddress().toString());
				Thread thread = new Thread(new HandleClient(ClientSocket, TManager, SList,ServerLog));
				thread.start();
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			ServSocket.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
